package com.lingshi.yingzaitownmap.controller;


import com.lingshi.yingzaitownmap.entity.domain.Event;
import com.lingshi.yingzaitownmap.entity.dto.PageDTO;
import com.lingshi.yingzaitownmap.entity.result.PageBean;
import com.lingshi.yingzaitownmap.entity.result.Result;
import com.lingshi.yingzaitownmap.service.EventService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/api/v1/events")
public class EventController {

    @Autowired
    private EventService eventService;

    /**
     * 获取活动列表
     *
     * @param eventPageDTO 分页参数
     * @return 活动列表
     */
    @GetMapping
    public Result<PageBean<Event>> getEvents(PageDTO eventPageDTO) {
        log.info("获取活动列表参数：{}", eventPageDTO);
        return Result.success(eventService.select(eventPageDTO));
    }

    /**
     * 获取活动详情
     *
     * @param id 活动id
     * @return 活动详情
     */
    @GetMapping("/{id}")
    public Result<Event> getEventById(@PathVariable String id) {
        log.info("获取活动id:{}", id);
        return Result.success(eventService.getById(id));
    }

}
